package com.zxq.demo.core.shutdown;

import cn.hutool.http.HttpUtil;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class ContextClosedListener {

    public static String destoryUrl = null;

    @EventListener
    public void handleContextClosed(ContextClosedEvent event) {
        System.out.println("Spring上下文已关闭，执行清理");
//        发送销毁请求
        // 注意：此时部分Bean可能已被销毁，避免依赖其他Bean
        HttpUtil.get(destoryUrl);
    }
}